use crate::R;
use axum::http::Uri;

/// [StatusCode::NOT_FOUND]回调函数
///
/// 如果没有路由与传入请求匹配，则将调用此服务。
/// # Example
/// ```
/// use axum::Router;
/// use axum::routing::get;
/// use axum_lib::not_found;
/// 
/// let app = Router::new()
///        .route("/root1", get(|| async { "hello world" }))
///        .fallback(not_found);
/// ```
pub async fn not_found(uri: Uri) -> R{
    let path = uri.path();
    let msg = format!("请求错误！路径为：{}。", path);
    R::fail(msg)
}

/// [StatusCode::METHOD_NOT_ALLOWED] 回调函数
///
/// 设置兜底所有以前注册的方法路由器，当没有设置匹配的方法处理程序时调用。
/// # Example
/// ```
/// use axum::Router;
/// use axum::routing::get;
/// use axum_lib::method_not_allowed;
/// 
/// let app = Router::new()
///        .route("/root1", get(|| async { "hello world" }))
///        .method_not_allowed_fallback(method_not_allowed);
/// ```
pub async fn method_not_allowed(uri: Uri) -> R{
    let path = uri.path();
    let msg = format!("请求方法不允许！路径为：{}。", path);
    R::fail(msg)
}